package com.shroo8.footballblog.controllers.api;

import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shroo8.footballblog.bo.api.CreateUserBo;
import com.shroo8.footballblog.dto.api.UserDto;

@Controller
public class CreateUserController {
	private static final Logger logger = LoggerFactory.getLogger(CreateUserController.class);

	@Resource(name="createUserBo", type=com.shroo8.footballblog.bo.api.CreateUserBoImpl.class)
	private CreateUserBo createUserBo;

	@RequestMapping(value = "/users", method = RequestMethod.POST)
	public @ResponseBody String createUser(Locale locale, @RequestParam("userType") String userType, 
			@RequestParam("userExternalId") String userExternalId, @RequestParam("userName") String userName, 
			@RequestParam("userScreenName") String userScreenName,@RequestParam("userPicUrl") String userPicUrl, 
			@RequestParam("userBigPicUrl") String userBigPicUrl, @RequestParam("userMiniPicUrl") String userMiniPicUrl) {

		logger.info("Welcome to createuser! The client locale is {}.", locale);
		
		UserDto userDto = new UserDto();
		userDto.setType(userType);
		userDto.setExternalId(userExternalId);
		userDto.setName(userName);
		userDto.setScreenName(userScreenName);
		userDto.setPicUrl(userPicUrl);
		userDto.setBigPicUrl(userBigPicUrl);
		userDto.setMiniPicUrl(userMiniPicUrl);
		
		return "{\"userId\":\""+ createUserBo.createUser(userDto) +"\"}"; 
	}


}
